﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace UniversityPortal.Models
{
    public class UPasswordValidationAttribute : ValidationAttribute
    {
        public double MinLength { get; set; }
        public int MaxLength { get; set; }

        public UPasswordValidationAttribute()
            : base("Wrong password length")
        {
        }

        public override bool IsValid(object value)
        {
            if (value == null)
            {
                return true;
            }

            var password = (string)value;
            if (password.Length < MinLength)
            {
                return false;
            }
            if (password.Length > MaxLength)
            {
                return false;
            }
            return true;
        }
    }
}